/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_VECTOR_H_
#define TRI_VECTOR_H_

#include <math.h>
#include <iostream>
#include "object.h"
#include "utils.h"


namespace tri
{

/**
 * TVector class
 */
class TVector : public TObject{
public:
    TVector();
    
    /**
     * Preset TVector values
     * 
     * @param x : X value
     * @param y : Y value
     * @param z : Z value
     */
    TVector(float x,float y,float z);
    TVector(float* v);
    virtual ~TVector();
    
    /**
     * Get object's String value
     */
    virtual std::string toString() const;
    
    /**
     * Geth Vector Lenght
     */
    float length();
    
    /**
     * Calculate the crossproduct of this vector and the given
     */
    tri::TVector crossProduct(tri::TVector* v);
    
    /**
     * Normalize vector
     */
    void normalize();
    
    /**
     * Get the vector dotProduct
     */
    float dotProduct(tri::TVector* v);
    
    //overload operators
    /**
     * Add vectors
     */
    tri::TVector& operator+=(const tri::TVector &v);
    
    /**
     * Subtract vectors
     */
    tri::TVector& operator-=(const tri::TVector &v);
    
    /**
     * Compare Vectors
     */
    bool operator==(const tri::TVector &v);
    
    /**
     * Divide vector 
     */
    tri::TVector& operator/=(const float &v);
    
    /**
     * Divide vector
     */
    tri::TVector operator/(const float &v);
    
    /**
     * Subtract vectors
     */
    tri::TVector operator-(const tri::TVector &v);
    
    /**
     * Scale vector
     */
    tri::TVector& operator*=(const float &v);
    
    /**
     * Scale vector
     */
    tri::TVector operator*(const float &v);
    
    float &operator[]( int ); 
    
    /**
     * Add vectors
     */
    tri::TVector operator+(const tri::TVector &v);
    friend std::ostream& operator<<( std::ostream&, const tri::TVector&);
    
    /**
     * Rotate vector
     */
    void rotateX(float angle);
    
    /**
     * Rotate vector
     */
    void rotateY(float angle);
    
    /**
     *Rotate Vector
     */
    void rotateZ(float angle);
    
    float x;
    float y;
    float z;
};
}

#endif /*VECTOR_H_*/
